import request from '@/utils/request.js'

// 申请注册
export const userRegisterService = (data)=> {
  return request.post('api/reg/', data)
}

// 登录
export const userLoginService = (username, password)=> {
  return request.post('api/login/', {username, password})
}

// 获取用户的基本资料
export const userProFileService = ()=> {
  return request.get('my/userinfo/')
}

// 保存用户的基本信息
export const userPutProFileService = (userForm)=> {
  return request.put('my/userinfo/', userForm)
}

// 获取文章分类列表
export const CateGetListService = () => {
  return request.get('my/cate/list/')
}

// 获取文章分类
export const CateGetService = (id) => {
  return request.get('my/cate/info/', id)
}

// 更新文章分类
export const CatePutService = (data) => {
  return request.put('my/cate/info/', data)
}

// 添加文章分类
export const CateAddService = (data) => {
  return request.post('my/cate/add/', data)
}

// 删除文章分类
export const CateDelService = (id) => {
  return request.delete(`my/cate/del/`, {
    params: { id: String(id) } // 强制转为 String 并作为 Query 参数
  })
}

// 获取文章列表
export const ArticleListGetService = (data) => {
  // 可以传递：state、cate_id、page_num、page_size
  // 返回值'id', 'title', 'content', 'cover_img', 'pub_date', 'state', 'cate_id', 'user_id'
  console.log('search:', data)
  return request.get('my/article/list/', {
    params: data
  })
}

// 获取文章详情
export const ArticleGetService = (id) => {
  return request.get('my/article/info/'+id+'/')
}

// 更新文章
export const ArticlePutService = (data) => {
  return request.put(`my/article/info/${data.id}/`, data)
}

// 删除文章
export const ArticleDelService = (id) => {
  return request.delete(`my/article/info/${id}/`)
}

// 添加新文章
export const ArticlePostService = (data) => {
  console.log('data:', data)
  return request.post('my/article/add/', data)
}

// 上传头像
export const AvatarUploadService = (data) => {
  return request.patch('my/update/avatar/', { avatar:data })
}

// 更新密码
export const PasswordRenewService = (data) => {
  return request.patch('my/updatepwd/', data)
}

